
import 'package:ysy_flutter_mvvm_yuanxuan/api/HttpService.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/base/BaseModel.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/base/PullPageBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/base/BaseBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/base/BaseListDataBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/detail/AddCartEntity.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/detail/GoodsDetailsBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/home/HomeAttentionPageBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/home/HomeCategoryTabBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/home/HomeAttentionBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/home/RecommendCategoryBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/home/RecommendGoodsBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ViewHelper.dart';
import '../../../bean/home/HomeContentBean.dart';

class GoodsDetailsVM extends BaseModel{

  GoodsDetailsBean?  detailsBean;
  int? like;
  int? collection;

  //商品详情页
  void getGoodsDetails({required String goodsId,bool isDialog=true,RequestDone? requestDone}){
     onNetWorkVerdictAndData(future: goodsDetails(goodsId), result: (str){
        detailsBean=BaseDataBean<GoodsDetailsBean>.fromJson(str,(map) => GoodsDetailsBean.fromJson(map)).data;
        like=detailsBean?.isLike;
        collection=detailsBean?.isCollection;
     },isDialog:isDialog,done: requestDone);
  }

  //收藏
  void onGoodsDetailsCollection({required String goodsId,bool isDialog=true,RequestDone? requestDone}){
    onNetWorkVerdictAndData(future: goodsDetailsCollection(goodsId), result: (str){
      collection=BaseStateDataBean<int>.fromJson(str).data;
    },isDialog:isDialog,done: requestDone);
  }

  //喜欢
  void onGoodsDetailsLike({required String goodsId,bool isDialog=true,RequestDone? requestDone}){
    onNetWorkVerdictAndData(future: goodsDetailsLike(goodsId), result: (str){
      like=BaseStateDataBean<int>.fromJson(str).data;
    },isDialog:isDialog,done: requestDone);
  }

  //加入购物车
  void onAddCart({required AddCartEntity addCartEntity,bool isDialog=true,RequestDone? requestDone}){
    onNetWorkVerdictAndData(future: addCart(addCartEntity), result: (str){
       showBottomToast("成功加入商品第一个sku 商品，不要问为什么，就是这样！");
    },isDialog:isDialog,done: requestDone);
  }

}